/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package atrevaluator;

import java.util.ArrayList;

/**
 * read jatr result files and compare the results to a refrence file.
 * INPUT: jatr result file (jatr output format), reference file (one line one term)
 * OUTPUT: precision.dat file that can be used for generating graphs with gnuplot
 * 
 * @author iknoth
 */
public class Main {

    public static String PREFIX = "/mnt/minerva1/nlp/projects/kiwi/iknoth";
    //public static String resultsFile = PREFIX + "/kiwi/atr/results/IntroductionToInformationRetrieval/CValue_ALGORITHM.txt";
    //public static String resultsFile = PREFIX + "/kiwi/atr/src/jatr_v1.0/test/IBM_GlossEx_ATR_ALGORITHM.txt";
    //public static String resultsFile = PREFIX + "/kiwi/atr/src/jatr_v1.0/test/LR_ATR_ALGORITHM.txt";
    
    //public static String resultsFolder = PREFIX + "/kiwi/atr/results/IntroductionToInformationRetrieval";
    public static String resultsFolder = PREFIX + "/kiwi/atr/results/genia";
    
    public static String referenceFile = PREFIX + "/kiwi/atr/corpora/genia/genia.terms.txt";
    //public static String referenceFile = PREFIX + "/kiwi/atr/corpora/IntroductionToInformationRetrievalReference/reference_index.txt";
    public static ArrayList<String> referenceFiles;    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        /*ArrayList<String> variants = new ArrayList<String>();
        variants.add("test");
        
        TermItem ti = new TermItem(variants, new Double(0.0));
        
        if (ti.equals("Test")) {
            System.out.println("success");
        } else {
            System.out.println("failure");
        }*/
        
        
        
        Main.referenceFiles = new ArrayList<String>();
        int numberOfResults = Integer.MAX_VALUE;
        if (args.length == 0) {
        
            //Main.referenceFiles.add(PREFIX + "/kiwi/atr/corpora/genia/gene_dictionary.txt");
            //Main.referenceFiles.add(PREFIX + "/kiwi/atr/corpora/genia/mesh2008.terms.txt");
            //Main.referenceFiles.add(PREFIX + "/kiwi/atr/corpora/genia/human_disease.obo.terms");
            Main.referenceFiles.add(Main.referenceFile);
        }
        else {
            numberOfResults = Integer.parseInt(args[1]);
            Main.resultsFolder = args[0];
            
            for (int i = 2; i < args.length; ++i) {
                Main.referenceFiles.add(args[i]);
            }
        }
        
        ATREvaluator atrEv = new ATREvaluator(Main.resultsFolder, Main.referenceFiles);

        atrEv.setNumberOfResults(numberOfResults);

        atrEv.evaluate();    
        
        GnuplotExporter gnuex = new GnuplotExporter(Main.resultsFolder);
        gnuex.export("showPrecision.png", "Precision", ".precision_dat");
        gnuex.export("showRecall.png", "Recall", ".recall_dat");
        gnuex.generateGraph();
        
        ArrayList<Integer> points = new ArrayList<Integer>();
        points.add(19);points.add(199);points.add(1999);//points.add(19999);
        LatexTableExport lte = new LatexTableExport(Main.resultsFolder);
        ArrayList<String> files = new ArrayList<String>();
        files.add("TF_ATR_ALGORITHM.precision_dat");
        files.add("TfIdf_ATR_ALGORITHM.precision_dat");
        files.add("RIDF_ATR_ALGORITHM.precision_dat");
        files.add("LR_ATR_ALGORITHM.precision_dat");
        files.add("MyWeirdness_ATR_ALGORITHM.precision_dat");
        files.add("MyTermEx_ATR_ALGORITHM.precision_dat");
        files.add("IBM_GlossEx_ATR_ALGORITHM.precision_dat");
        files.add("CValue_ALGORITHM.precision_dat");
        files.add("Voting_MyWeirdness_Tfidf.precision_dat");
        files.add("Voting_LR_Tfidf.precision_dat");
        files.add("Voting_ALL.precision_dat");
        
        lte.setFiles(files);
        lte.export(points);
        
    }

}
